{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "def generate_data(args):\n",
    "    \"\"\"\n",
    "    This implements the generative process of [1], but using larger feature and\n",
    "    latent spaces ([1] assumes ``feature_dim=1`` and ``latent_dim=5``).\n",
    "    \"\"\"\n",
    "    z = dist.Bernoulli(0.5).sample([args.num_data])\n",
    "    x = dist.Normal(z, 5 * z + 3 * (1 - z)).sample([args.feature_dim]).t()\n",
    "    t = dist.Bernoulli(0.75 * z + 0.25 * (1 - z)).sample()\n",
    "    y = dist.Bernoulli(logits=3 * (z + 2 * (2 * t - 2))).sample()\n",
    "\n",
    "    # Compute true ite for evaluation (via Monte Carlo approximation).\n",
    "    t0_t1 = torch.tensor([[0.0], [1.0]])\n",
    "    y_t0, y_t1 = dist.Bernoulli(logits=3 * (z + 2 * (2 * t0_t1 - 2))).mean\n",
    "    true_ite = y_t1 - y_t0\n",
    "    return x, t, y, true_ite"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pyro\n",
    "import argparse\n",
    "import logging\n",
    "import torch\n",
    "import pyro.distributions as dist\n",
    "import pandas as pd\n",
    "\n",
    "if __name__ == \"__main__\":\n",
    "    assert pyro.__version__.startswith(\"1.8.1\")\n",
    "    parser = argparse.ArgumentParser(\n",
    "        description=\"dataset generator\"\n",
    "    )\n",
    "    parser.add_argument('-f')\n",
    "    parser.add_argument(\"--num-data\", default=30000, type=int)\n",
    "    parser.add_argument(\"--feature-dim\", default=10, type=int)\n",
    "    args = parser.parse_args()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(30000, 13)\n"
     ]
    }
   ],
   "source": [
    "x, t, y, true_ite = generate_data(args)\n",
    "x, t, y, true_ite = pd.DataFrame(x.numpy()),  pd.DataFrame(t.numpy()),  pd.DataFrame(y.numpy()),  pd.DataFrame(true_ite.numpy())\n",
    "data = pd.concat((x,t,y,true_ite), axis = 1)\n",
    "data.columns = [['x0', 'x1','x2','x3','x4','x5','x6','x7','x8','x9','treatment','y','true_ite']]\n",
    "print(data.shape)\n",
    "data.head()\n",
    "data.to_csv('10_dim_x_y_ite_30000_sample.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
